package com.photolibrary.base;

import android.support.annotation.NonNull;
import android.widget.ImageView;

import com.photolibrary.base.load.IMediaLoader;


/**
 * 作者： ch
 * 时间： 2018/4/10 0010-上午 10:43
 * 描述：
 * 来源：
 */


public class BaseMediaLoader {
    private static BaseMediaLoader mediaLoader;
    private IMediaLoader iMediaLoader;

    public static BaseMediaLoader getInstance() {

        if (mediaLoader == null) {
            mediaLoader = new BaseMediaLoader();
        }
        return mediaLoader;
    }

    public void init(@NonNull IMediaLoader loader) {
        this.iMediaLoader = loader;
    }

    public void displayThumbnail(@NonNull ImageView img, @NonNull String path, int width, int height) {
        if (iMediaLoader == null) {
            throw new IllegalStateException("init method should be called first");
        }
        iMediaLoader.displayThumbnail(img, path, width, height);
    }

    public void displayIMG(@NonNull ImageView img, @NonNull String path, int width, int height) {
        if (iMediaLoader == null) {
            throw new IllegalStateException("init method should be called first");
        }
        iMediaLoader.displayIMG(img, path, width, height);
    }


    public void displayIMGNocrop(ImageView img, @NonNull String absPath) {
        if (iMediaLoader == null) {
            throw new IllegalStateException("init method should be called first");
        }
        iMediaLoader.displayIMGNocrop(img, absPath);
    }

    public void downImg(String url, IMediaLoader.FileCallBack callBack) {
        if (iMediaLoader == null) {
            throw new IllegalStateException("init method should be called first");
        }
        iMediaLoader.downImg(url, callBack);
    }
}
